package org.melanesia.converters.jdbc;

import java.sql.Statement;
import java.sql.Types;

import org.melanesia.converters.JavaToJdbcConverter;
import org.melanesia.converters.TypeConverter;

/**
 * Default converter from Enum do JDBC type. Converts enum to it's string
 * representation using <code>name()</code> method, and defines it as a
 * <code>Types#VARCHAR</code> JDBC type.
 *
 * @author marcin.kielar
 */
public final class EnumNameToJdbcConverter extends JavaToJdbcConverter {

    @Override
    public int getJdbcType(final TypeConverter typeConverterContext) {
        return Types.VARCHAR;
    }

    @Override
    public Object convert(final TypeConverter typeConverterContext, final Object value, final Statement stmt,
            final String parameterName) {
        return ((Enum<?>) value).name();
    }
}
